import request from '@/utils/request.ts'
import type {
  UserResponseData,
  UserRoleListResponseData,
} from '@/api/acl/user/type.ts'
enum API {
  //获取用户列表
  USER_LIST_URL = '/admin/acl/user',
  //删除用户
  DELETE_USER_URL = '/admin/acl/user/remove/',
  //添加用户
  ADD_USER_URL = '/admin/acl/user/save',
  //更新用户
  UPDATE_USER_URL = '/admin/acl/user/update',

  //为用户分配角色
  ASSIGN_ROLE_URL = '/admin/acl/user/doAssignRole',

  //获取用户角色信息
  USER_ROLE_URL = '/admin/acl/user/toAssign/',
}

export const reqUserList = (page: number, limit: number, username?: string) => {
  return request.get<any, UserResponseData>(
    API.USER_LIST_URL +
      `/${page}/${limit}${username ? `?username=${username}` : ``}`,
  )
}

export const reqDeleteUser = (id: number) => {
  return request.delete<any, any>(API.DELETE_USER_URL + id)
}

export const reqAddUser = (user: any) => {
  return request.post<any, any>(API.ADD_USER_URL, user)
}

export const reqUpdateUser = (user: any) => {
  return request.post<any, any>(API.UPDATE_USER_URL, user)
}
//获取用户角色信息
export const reqUserRoleList = (userId: number) => {
  return request.get<any, UserRoleListResponseData>(API.USER_ROLE_URL + userId)
}

//为用户分配角色
export const reqAssignRole = (data: any) => {
  return request.post<any, any>(API.ASSIGN_ROLE_URL, data)
}
